<html>
<head><meta charset="utf-8"><title>should String::drain() w/ overflow incl range panic #72237 · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html">should String::drain() w/ overflow incl range panic #72237</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198360509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360509">(May 21 2020 at 18:50)</a>:</h4>
<p>hi <span class="user-group-mention" data-user-group-id="2645">@T-libs</span> . We discussed <a href="https://github.com/rust-lang/rust/issues/72237">#72237</a> at the <a href="https://zulip-archive.rust-lang.org/238009tcompilermeetings/41446weeklymeeting2020052154818.html#198329689">T-compiler meeting today</a>, and there was some contention as to whether this was even a bug at all.</p>



<a name="198360609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360609">(May 21 2020 at 18:51)</a>:</h4>
<p>what's the argument for it not being a bug?</p>



<a name="198360632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360632">(May 21 2020 at 18:51)</a>:</h4>
<p>i wish <span class="user-mention" data-user-id="119031">@Esteban Küber</span> had spelled their opinion here out more</p>



<a name="198360722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360722">(May 21 2020 at 18:52)</a>:</h4>
<p>or oh</p>



<a name="198360749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360749">(May 21 2020 at 18:52)</a>:</h4>
<p>maybe <span class="user-mention" data-user-id="119031">@Esteban Küber</span> 's point wasn't about whether the current behavior is buggy</p>



<a name="198360761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360761">(May 21 2020 at 18:52)</a>:</h4>
<p>but rather about whether it would be better to DWIM here</p>



<a name="198360800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360800">(May 21 2020 at 18:52)</a>:</h4>
<p>The latter</p>



<a name="198360802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360802">(May 21 2020 at 18:52)</a>:</h4>
<p>this <a href="https://zulip-archive.rust-lang.org/238009tcompilermeetings/41446weeklymeeting2020052154818.html#198330285">comment</a>:</p>
<blockquote>
<p>If we change the impls of drain to accept this off by one case we can make it work as the original code intended, otherwise itd be much nicer for it to be a compile time error instead of a panic. If we want it to be a panic then the patch is minimal</p>
</blockquote>



<a name="198360833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360833">(May 21 2020 at 18:53)</a>:</h4>
<p>so okay, that's <em>definitely</em> a T-libs call</p>



<a name="198360882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360882">(May 21 2020 at 18:53)</a>:</h4>
<p>The entire point of ..= existing is to avoid these off by one errors, after all <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="198360899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198360899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198360899">(May 21 2020 at 18:53)</a>:</h4>
<p>it should definitely panic if it compiles, yeah</p>



<a name="198361002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198361002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198361002">(May 21 2020 at 18:54)</a>:</h4>
<p>there could be a lint for "statically out-of-bounds bounds" but I don't feel super strongly about that</p>



<a name="198361524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198361524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198361524">(May 21 2020 at 18:58)</a>:</h4>
<p>I mean, there is in some sense -- if we detect it, we'll say something like "this code will panic at runtime" -- but I imagine we'll not get there for a long time :)</p>



<a name="198361948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198361948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198361948">(May 21 2020 at 19:01)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> i fear that I am either not understanding your proposal or not communicating it properly</p>



<a name="198361986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198361986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198361986">(May 21 2020 at 19:01)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> can you state what <em>you</em> mean, in the "DWIM" case here?</p>



<a name="198362115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198362115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198362115">(May 21 2020 at 19:02)</a>:</h4>
<p>i.e., by "accept this off by one case", I take that to mean: "there is a sensible non-panicking and non-erroring semantics here. Use it."</p>



<a name="198362171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/198362171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#198362171">(May 21 2020 at 19:03)</a>:</h4>
<p>but I would prefer if you wrote out your intention rather than have me attempt to infer it or reconstruct it.</p>



<a name="205361158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/should%20String%3A%3Adrain%28%29%20w/%20overflow%20incl%20range%20panic%20%2372237/near/205361158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/should.20String.3A.3Adrain().20w.2F.20overflow.20incl.20range.20panic.20.2372237.html#205361158">(Jul 29 2020 at 14:08)</a>:</h4>
<p>I have discovered this issue today using <a href="https://github.com/jakubadamw/rutenspitz">https://github.com/jakubadamw/rutenspitz</a> and I'm going to go ahead and open a PR making it panic unless someone voices objections.<br>
(context: <a href="https://github.com/rust-lang/rust/issues/72237">https://github.com/rust-lang/rust/issues/72237</a>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>